<?php
namespace app\common\logic;

use app\admin\logic\system\Config as SystemConfig;
use app\common\exception\LogicException;
use app\school\logic\school\School;
use app\school\logic\school\SchoolSplitConfig;

/**
 * 分成配置
 */
class SplitConfig
{

    public static function get($mhm_id = 0)
    {
        // 平台比例
        $split_config = SystemConfig::get("split.config", []);

        // 机构比例
        if ( 1 != $mhm_id ) {
            
            $mhm_split_config  = app(SchoolSplitConfig::class)->getSplitConfig($mhm_id);

            if ( $mhm_split_config ) {
                $split_config = $mhm_split_config; 
            } else {
                // 机构等级
                $school_level_info  = app(School::class)->getSchoolLevelInfo($mhm_id);

                if ( $school_level_info && !empty($school_level_info->level_info) ) {

                    $level_info     = $school_level_info->level_info;
                    $proportion     = is_array($level_info) ? $level_info['proportion'] : $level_info->proportion;

                    if ( $proportion ) {
                       $split_config['platform'] = $split_config['platform'] + $split_config['school'] - $proportion; 
                       $split_config['school']   = $proportion;
                   }
                }
            }  
        }

        return $split_config;
    }
}
